home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Fun House 1
/
CD Fun House (Wayzata Technology).iso
/
•Word Games•
/
WordFind •••
/
Source
/
wordsearch.new
< prev
Wrap
Text File
|
1987-11-14
|
12KB
|
431 lines
(**)
(*This is an attempt to write a generic word search program*)
(*The idea will be that the user will type in a list of words and the computer will *)
(*put the words into a large matrix and then print out that matrix with the words *)
(*underneath it*)
(*This new version contains a multicolumn option that prints with tabs*)
(*11/9 added repeat through loop so that you can make multiple puzzles*)
(*11/9 mixed in code from spanish version to make one unified *)
(*multilingual version*)
PROGRAM wordsearch;
USES
placepuzzle, stringf, sorts;
CONST
VERSION = '1.3fl';
TYPE
location = RECORD
x : integer;
y : integer;
END;
VAR
wordcount, i, j, k, numcol : integer;
fname : STRING;
ff : text;
answer : STRING;
screen : Rect;
reptest : boolean;
ok : boolean;
PROCEDURE initmat;
VAR
i, j : integer;
BEGIN
FOR i := 1 TO XMAX DO
FOR j := 1 TO YMAX DO
BEGIN
puzzle[i, j].ch := ' ';
puzzle[i, j].boldf := false;
END;
FOR i := 1 TO MAXWORDS DO
ourlist[i] := ' ';
END;
PROCEDURE copyright;
BEGIN
writeln('WordFind version ', VERSION);
writeln('(c) 1987 Matthew Weinstein');
writeln('Portions copyright by THINK Technologies, Inc.');
writeln;
writeln;
writeln('Working on this project confirmed everything I always thought about PASCAL');
writeln('It is back to C forever for me!');
writeln('Next step is to give this a mac interface.');
writeln('Feel free to give both source code and program to whomever...');
writeln('Just include this copyright');
writeln('Also if you feel like donating any money to the cause (NO obligation)');
writeln(' send it to : ');
writeln('Matthew Weinstein; 2128 Hayes St.;San Francisco, CA 94117');
writeln;
END;
FUNCTION readlist : boolean;
VAR
c : char;
k : integer;
BEGIN
wordcount := 1;
WHILE (ourlist[wordcount] <> '2') AND (ourlist[wordcount] <> '3') AND (wordcount < MAXWORDS) DO
BEGIN
readln(ourlist[wordcount]);
upper(ourlist[wordcount]);
sstrip(ourlist[wordcount]);
IF length(ourlist[wordcount]) > 0 THEN {catch all carriage returns}
IF ourlist[wordcount] = '1' THEN
BEGIN
wordcount := 1;
writeln;
writeln('Start again.');
writeln;
END
ELSE IF ourlist[wordcount] = '2' THEN
readlist := false
ELSE IF ourlist[wordcount] = '3' THEN
readlist := true
ELSE
BEGIN
makealpha(ourlist[wordcount]);
IF length(ourlist[wordcount]) > 0 THEN {is there anything left after stripping non alphas}
wordcount := wordcount + 1;
END;
END;
IF wordcount = MAXWORDS THEN
readlist := true;
wordcount := wordcount - 1;
END;
{ fill in random letters wherever there is a space }
{ fill in random letters wherever there is a space }
PROCEDURE fillpuzzle;
VAR
i, j : integer;
BEGIN
FOR i := 1 TO XMAX DO
FOR j := 1 TO YMAX DO
IF puzzle[i, j].ch = ' ' THEN
puzzle[i, j].ch := upalpha[randnum(alphsize)];
END;
PROCEDURE writelist (numc : integer);
CONST
COLWIDTH = 20;
VAR
k, j, i : integer;
thisword, nextword : integer;
colsize : integer;
colextra : integer;
BEGIN
colsize := wordcount DIV numc;
colextra := wordcount MOD numc;
IF colextra <> 0 THEN
colsize := colsize + 1;
FOR j := 1 TO colsize DO
FOR i := 1 TO numc DO
BEGIN
IF (i <= colextra) OR (colextra = 0) THEN
BEGIN
thisword := j + (i - 1) * colsize;
nextword := j + i * colsize;
END
ELSE
BEGIN
thisword := j + colextra * colsize + (i - 1 - colextra) * (colsize - 1);
nextword := j + colextra * colsize + (i - colextra) * (colsize - 1);
END;
(* only print the word if we are in the colextra region or if we are less than colsize*)
IF (thisword <= wordcount) AND ((i <= colextra) OR (j < colsize) OR (colextra = 0)) THEN
write(ourlist[thisword]);
IF (i = numc) THEN
writeln
ELSE IF (thisword < wordcount) AND NOT (nextword > wordcount) THEN
IF length(ourlist[thisword]) <= COLWIDTH THEN
FOR k := 1 TO COLWIDTH - length(ourlist[thisword]) DO
write(' ');
END;
END;
PROCEDURE printoutlist (numc : integer);
CONST
COLWIDTH = 20;
VAR
k, j, i : integer;
thisword, nextword : integer;
colsize : integer;
colextra : integer;
BEGIN
colsize := wordcount DIV numc;
colextra := wordcount MOD numc;
IF colextra <> 0 THEN
colsize := colsize + 1;
FOR j := 1 TO colsize DO
FOR i := 1 TO numc DO
BEGIN
IF (i <= colextra) OR (colextra = 0) THEN
BEGIN
thisword := j + (i - 1) * colsize;
nextword := j + i * colsize;
END
ELSE
BEGIN
thisword := j + colextra * colsize + (i - 1 - colextra) * (colsize - 1);
nextword := j + colextra * colsize + (i - colextra) * (colsize - 1);
END;
(* only print the word if we are in the colextra region or if we are less than colsize*)
IF (thisword <= wordcount) AND ((i <= colextra) OR (j < colsize) OR (colextra = 0)) THEN
write(ff, ourlist[thisword]);
IF (i = numc) THEN
writeln(ff)
ELSE IF (thisword < wordcount) AND NOT (nextword > wordcount) THEN
IF length(ourlist[thisword]) <= COLWIDTH THEN
FOR k := 1 TO COLWIDTH - length(ourlist[thisword]) DO
write(ff, ' ');
END;
END;
PROCEDURE printlist (numc : integer);
VAR
j, i : integer;
colsize : integer;
colextra : integer;
thisword, nextword : integer;
BEGIN
writeln(ff); (* place a blank line between the puzzle and the list *)
colsize := wordcount DIV numc;
colextra := wordcount MOD numc;
IF colextra <> 0 THEN
colsize := colsize + 1;
FOR j := 1 TO colsize DO
FOR i := 1 TO numc DO
BEGIN
IF (i <= colextra) OR (colextra = 0) THEN
BEGIN
thisword := j + (i - 1) * colsize;
nextword := j + i * colsize;
END
ELSE
BEGIN
thisword := j + colextra * colsize + (i - 1 - colextra) * (colsize - 1);
nextword := j + colextra * colsize + (i - colextra) * (colsize - 1);
END;
IF (thisword <= wordcount) AND ((i <= colextra) OR (j < colsize) OR (colextra = 0)) THEN
write(ff, ourlist[thisword]);
IF i = numc THEN
writeln(ff)
(* print a tab if this word is less than word count and the next word # is greater than word count*)
ELSE IF (thisword < wordcount) AND NOT (nextword > wordcount) THEN
write(ff, chr(9)) (* tab *)
END;
END;
PROCEDURE printpuzzle;
VAR
i, j : integer;
BEGIN
FOR i := 1 TO YMAX DO
BEGIN
FOR j := 1 TO XMAX DO
BEGIN
write(ff, puzzle[j, i].ch, ' ');
END;
writeln(ff);
END;
END;
PROCEDURE writepuzzle;
VAR
i, j : integer;
BEGIN
FOR i := 1 TO YMAX DO
BEGIN
FOR j := 1 TO XMAX DO
BEGIN
write(puzzle[j, i].ch, ' ');
END;
writeln;
END;
END;
PROCEDURE writeanswer;
VAR
i, j : integer;
BEGIN
FOR i := 1 TO YMAX DO
BEGIN
FOR j := 1 TO XMAX DO
BEGIN
IF puzzle[j, i].boldf = true THEN
write(puzzle[j, i].ch, ' ')
ELSE
write(' ', ' ');
END;
writeln;
END;
END;
PROCEDURE printanswer;
VAR
i, j : integer;
BEGIN
FOR i := 1 TO YMAX DO
BEGIN
FOR j := 1 TO XMAX DO
BEGIN
IF puzzle[j, i].boldf = true THEN
write(ff, puzzle[j, i].ch, ' ')
ELSE
write(ff, ' ', ' ');
END;
writeln(ff);
END;
END;
BEGIN
(* for each language implementation these 2 lines have to*)
(*be changed*)
upalpha := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
lowalpha := 'abcdefghijklmnopqrstuvwxyz';
screen.top := 40;
screen.bottom := 335;
screen.left := 5;
screen.right := 500;
setTextRect(screen);
ShowText;
copyright;
REPEAT
BEGIN
writeln;
writeln;
REPEAT
write('Enter random number from 1 to 5000; 0 to quit: ');
readln(randSeed);
UNTIL randseed >= 0;
IF randseed <> 0 THEN
BEGIN
writeln;
REPEAT
write('How many across should the puzzle be? (less or equal to ', MAXX : 3, ') ');
readln(XMAX);
UNTIL (XMAX <= MAXX) AND (XMAX > 1);
REPEAT
write('How many down should the puzzle be? (less or equal to ', MAXY : 3, ') ');
readln(YMAX);
UNTIL (YMAX <= MAXY) AND (YMAX > 1);
writeln('Setting up the puzzle...');
initmat;
writeln;
writeln('Type "1" to START OVER.');
writeln('Type "2" to QUIT.');
writeln('Type "3" when done.');
writeln('Enter the words to be wordsearched: (Hit return after each.)');
writeln;
IF readlist = true THEN{get the list of words}
BEGIN
write('Working');
ssort1(wordcount); {put in size order}
i := 0;
WHILE i <> wordcount DO
BEGIN
i := i + 1;
write('.'); (*let the folks know were there*)
IF rightlen(ourlist[i]) = true THEN
BEGIN
j := 0;
REPEAT
ok := placerandom(ourlist[i]);
j := j + 1;
UNTIL (j = 20) OR (ok = true);
IF ok = false THEN
IF placeanyplace(ourlist[i]) = false THEN
BEGIN
writeln('Can not place ', ourlist[i]);
IF i <> wordcount THEN
FOR j := i TO wordcount - 1 DO
ourlist[j] := ourlist[j + 1];
wordcount := wordcount - 1;
i := i - 1;
END; (*placeanyplace*)
END(* rightlen *)
ELSE (*rightlen*)
BEGIN
writeln;
writeln(ourlist[i], ' is too large to fit in a ', XMAX : 3, ' by ', YMAX : 3, ' puzzle.');
IF i <> wordcount THEN
FOR j := i TO wordcount - 1 DO
ourlist[j] := ourlist[j + 1];
wordcount := wordcount - 1;
i := i - 1; (* done so incrementer looks at new ith word*)
END;
END; (* for i *)
IF wordcount > 0 THEN
BEGIN
writeln;
fillpuzzle;
writeln;
REPEAT
write('How many columns across should I print the clues? ');
readln(numcol);
UNTIL numcol < wordcount;
writeln;
writepuzzle;
writeln;
ssort2(wordcount);
writelist(numcol);
writeln;
writeln('Type "NONE" for no save.');
Writeln('Type "PRINTER:" to print out puzzle.');
writeln('Type "QUIT" to quit.');
write('Enter file to save your puzzle: ');
readln(fname);
upper(fname);
sstrip(fname);
IF fname <> 'QUIT' THEN
BEGIN
IF fname <> 'NONE' THEN
BEGIN
rewrite(ff, fname);
printpuzzle;
IF fname <> 'PRINTER:' THEN
printlist(numcol)
ELSE
printoutlist(numcol);
close(ff);
END;
writeln;
write('Print solution (Y or N)? ');
readln(answer);
upper(answer);
sstrip(answer);
IF answer[1] = 'Y' THEN
BEGIN
writeanswer;
writeln;
Writeln('Type "PRINTER:" to print out solution.');
writeln('Type "QUIT" to quit.');
write('Enter file to save your solution: ');
readln(fname);
upper(fname);
sstrip(fname);
IF fname <> 'QUIT' THEN
BEGIN
rewrite(ff, fname);
printanswer;
close(ff);
END;
END;
END;
END (*wordlist*)
ELSE
BEGIN
writeln;
writeln('No words fit into the puzzle; try again.');
write('Hit return to continue');
readln(answer);
END;
END; {readlist}
END; (* randseed*)
END;
writeln;
write('Make another puzzle (Y or N)? ');
readln(answer);
upper(answer);
sstrip(answer);
IF answer[1] = 'Y' THEN
reptest := true
ELSE
reptest := false;
UNTIL reptest = false;
END.